#import "RootViewController.h"

@implementation RootViewController

- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    return YES;
}

#pragma mark -
#pragma mark View lifecycle

- (void)viewDidLoad {
    [super viewDidLoad];	
	labelList = [NSArray arrayWithObjects:
                 NSLocalizedString(@"My Tasks", @"label.MyTask"),
                 NSLocalizedString(@"Offered Tasks", @"label.OfferedTask"),
                 nil];
	controllerList = [NSArray arrayWithObjects:
                      workitemListViewController,
                      offeredListViewController,
                      nil];
	[labelList retain];
	[controllerList retain];
}

#pragma mark -
#pragma mark Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [controllerList count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
	static NSString *CellIdentifier = @"RootCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
		cell.textLabel.text = [labelList objectAtIndex: indexPath.row];
		cell.textLabel.font = [UIFont fontWithName:@"Arial" size:16.0];
		cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    return cell;
}

#pragma mark -
#pragma mark Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [self.navigationController pushViewController: [controllerList objectAtIndex: indexPath.row] animated:YES];
}


#pragma mark -
#pragma mark Memory management

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    }

- (void)viewDidUnload {
}

- (void)dealloc {
	[labelList dealloc];
	[controllerList dealloc];
    [super dealloc];
}


@end

